<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.all.js"  charset="utf-8"></script>

</head>
<body>
<div class="layui-form-item">
    <label class="layui-form-label">名称</label>
    <div class="layui-input-inline">
        <input type="text" required lay-verify="required" id="name" class="layui-input">
    </div>
    <button type="button" id="btn1" class="layui-btn  ">
        <i class="layui-icon">&#xe615;</i>
    </button>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength" id="del">批量删除</button>
    </div>
</script>
<table id="demo" lay-filter="list"></table>
<script type="text/javascript">
    layui.use(['table','layer'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.$;

        //表格渲染开始
        table.render({
            elem: '#demo'
            ,height: 312
            ,url: '${pageContext.request.contextPath}/log/selectAll' //数据接口
            ,limit:5
            ,limits:[5,10,15]
            ,page: true //开启分页
            ,toolbar: '#toolbarDemo'
            ,cols: [[ //表头
                {type:'checkbox',fixed: 'left'}
                ,{field: 'logId', title: 'ID', sort: true, fixed: 'left'}
                ,{field: 'logIp', title: 'Ip'}
                ,{field: 'logDate', title: '时间', sort: true}
                ,{field: 'logContent', title: '内容'}
                ,{field:'logType',title:'类型'}
            ]]
        });
        //表格渲染结束--------------




        //查询开始--------------
        $("#btn1").click(function () {
            table.reload('demo', {
                where: {
                    logType: $("#name").val()
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            })

        })
        //查询结束--------------

        //批量删除开始-------------------
        $("#del").click(function () {
            console.log("aa")
            var a=[];
            table.on('toolbar(list)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                console.log(data)
                $(data).each(function (i,o) {
                    a[i]=o.logId;
                })
                console.log(a.length)
                $.ajax({

                    url:'${pageContext.request.contextPath}/log/deleteByIds?ids='+a,
                    success:function (result) {
                        if(result.flag){
                            table.reload('demo');       //表格重载
                            layer.msg("删除成功");       //提示消息
                        }
                    }
                })
            });

        })
        // 批量删除结束-------------------

    });
</script>
</body>
</html>
